package com.hfjava.herundong.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class AccessTokenUtil {
    public static String ACCESSTOKEN;
    static final String APPID ="wx775d40e24db7c889";
    static final String APPSECRET ="3ea4175f97c5bae832d917f7ede9d1be";

    public static void main(String[] args) throws Exception {
        URL url =new URL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();


        BufferedReader br = new BufferedReader(
                new InputStreamReader(con.getInputStream(), "utf-8")
        );

        String str;
        StringBuffer sb = new StringBuffer();

        while ((str = br.readLine()) != null) {
            sb.append(str);
        }

        System.out.println(sb);
    }
    public static void findAccessToken() throws Exception{
        URL url =new URL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();

        BufferedReader br = new BufferedReader(
                new InputStreamReader(con.getInputStream(), "utf-8")
        );

        String str;
        StringBuffer sb = new StringBuffer();

        while ((str = br.readLine()) != null) {
            sb.append(str);
        }

        System.out.println(sb);
    }
}
